<?php
/*
Write date to xml file use "example.php?w=1"
*/

require_once("../functions.php");
gadget_write();
html_header();

//Below gadget contents
?>
<style>
<!--
.ct_input_text {
	border:1px solid #858585; 
}

body,p{font-family:arial}
a.bluelink:link{color:#0000cc;}
a.bluelink:hover{color:#0000cc;}
a.bluelink:visited{color:#800080;}
-->
</style>

<span id="result"></span><br />
<span id="suanshi"></span>&nbsp;=  <input style="width:30px;" type="text" size="2" id="youinput" title="Enter to sumit" class="ct_input_text">  &nbsp; &nbsp;
<button onClick="judge()">Go</button>

<script>
function GetRandomNumber(lbound, ubound) 
{
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

var suanshi;

function init() {
	var var1 = GetRandomNumber(10,99);
	var var2 = GetRandomNumber(10,99);
	suanshi = var1 + " + " +  var2;
	document.getElementById("suanshi").innerHTML = suanshi;

	var youinput = document.getElementById("youinput");

	if (youinput.addEventListener)
		youinput.addEventListener("keypress", filter, false);
    else {
		youinput.onkeypress = filter;
    }

    ///document.getElementById("youinput").focus();
}

function filter(event) {
        // Get the event object and character code in a portable way
        var e = event || window.event;         // Key event object
        var code = e.charCode || e.keyCode;    // What key was pressed
	if(code == 13) {
		judge();
	}
}

function judge() {
	var youinput = document.getElementById("youinput");
	var result = document.getElementById("result");
	var flag = false;
	var msg = "";
	
	if(youinput.value == eval(suanshi)) {
		msg += " <font color=green> √ </font>";	
	} else {
	    msg += " <font color=red> ×  </font>";
	}

	msg += suanshi + "=" + eval(suanshi) + " &nbsp; &nbsp; (Your: " + youinput.value + ")";
		
	result.innerHTML = msg;

	init();

	youinput.value="";
	youinput.focus();
}

init();

</script>

<?php
html_footer();
?>
